package self.hoy.demo.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author hyh
 * @date 2020/6/7
 */
public class ConnectionUtils {

    /**
     * 获取MQ链接
     * @return
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义一个链接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("127.0.0.1");
        //AMQP
        factory.setPort(5672);
        factory.setUsername("hoy");
        factory.setPassword("123456");
        factory.setVirtualHost("/hoy_vhost");

        return factory.newConnection();
    }
}
